package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


import com.example.myapplication.R;
import com.example.myapplication.ShuJu.MyconsultationBean;
import com.example.myapplication.lawyer.IDLawyerconsultationtActivity;


import java.util.List;

public class ConsultationlistApter extends  RecyclerView.Adapter<ConsultationlistApter.Myhot>{
    private Context context;
    private List<MyconsultationBean.RowsBean> list;


    public ConsultationlistApter(Context context, List<MyconsultationBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ConsultationlistApter.Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_consultationlist, null);
        return new ConsultationlistApter.Myhot(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ConsultationlistApter.Myhot holder, int position) {
        holder.title_consultationlist.setText(list.get(position).getLawyerName());
        holder.text_expertise.setText(list.get(position).getLegalExpertiseName());
        holder.time_consultationlist.setText(list.get(position).getCreateTime());
        if("0".equals(list.get(position).getState())){
            holder.status_consultationlist.setText("状态:未处理");
        }else  if("1".equals(list.get(position).getState())){
            holder.status_consultationlist.setText("状态:已处理");
        }
        //进入咨询详情页
        holder.re_consultationlist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, IDLawyerconsultationtActivity.class);
                intent.putExtra("LawyerconsultationtActivityID",String.valueOf(list.get(position).getId()));
                intent.putExtra("LawyerconsultationtActivityLawyerId",String.valueOf(list.get(position).getLawyerId()));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class Myhot extends RecyclerView.ViewHolder{

        private final ImageView img_consultationlist;
        private final TextView title_consultationlist;
        private final TextView text_expertise;
        private final TextView status_consultationlist;
        private final TextView time_consultationlist;
        private final RelativeLayout re_consultationlist;

        public Myhot(@NonNull View itemView) {
            super(itemView);
            img_consultationlist = itemView.findViewById(R.id.img_consultationlist);
            re_consultationlist = itemView.findViewById(R.id.re_consultationlist);
            title_consultationlist = itemView.findViewById(R.id.title_consultationlist);
            text_expertise = itemView.findViewById(R.id.text_expertise);
            status_consultationlist = itemView.findViewById(R.id.status_consultationlist);
            time_consultationlist = itemView.findViewById(R.id.time_consultationlist);
        }
    }
}
